home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / fsserial.zip / ANSIVIEW.PAS next >
Pascal/Delphi Source File  |  1991-01-29  |  20KB  |  705 lines

  1. Unit AnsiView;
  2.  
  3. {     ANSIVIEW.PAS - 24 January 1991
  4.  
  5.                           By Marcos R. Della
  6.                              5084 Rincon Ave.
  7.                              Santa Rosa, CA 95409
  8.  
  9.                              CIS: 71675,765
  10.  
  11.       This Unit was written so that I had something that reminded me of the
  12.       original WRITELN and WRITE statments of pascal where I was working
  13.       with the screen and there were various definate controls I had using
  14.       the GOTOXY and CLRSCR routines.  Under TVision, you no longer have
  15.       these controls and need to learn a completely different way of getting
  16.       info on the screen.
  17.  
  18.       AnsiView was written to give you some of these old methods while still
  19.       using the TVision platform. That is, your screen is a scroll window of
  20.       your size choosing (You can define a screen 128,2048 and use the gotoxy
  21.       to get to anywhere on that screen!)  Also if you turn on the ANSI
  22.       option, the driver will recognise ANSI controls (For reading those ANSI
  23.       files directly and displaying them!)
  24.  
  25.       Because this is also a TVision enviroment, your screen will also be
  26.       saved if you do a desktop save! Wonderful stuff eh?
  27.  
  28.  
  29.       NOTE!!!   Registration values used by this Unit
  30.  
  31.                     TANSIView = 7200;
  32.                     TInterior = 7201;
  33.  
  34.       --------------------
  35.       Modification History
  36.       --------------------
  37.  
  38.       29 January 1991 - Added the code to handle 15 of the ANSI control
  39.                         characters if they are passed to the ANSIView
  40.       routines.  There are two commands that will no work with this current
  41.       implementation. The <ESC>[xP and <ESC>[x@ for insert and delete
  42.       characters on the current line.  These should be supported in the
  43.       near future whenever I get back to working on this unit...
  44.  
  45.       There is a problem with the cursor positioning not always updating
  46.       the onscreen cursor display (if you have it on) however with the
  47.       printing of any character or other command, it comes back on. I'm
  48.       still scratching my head over this one.
  49. }
  50.  
  51. {$F+,O+,R-,S-}
  52.  
  53. Interface
  54.  
  55. Uses Dos, Drivers, Views, Objects, Memory;
  56.  
  57. CONST MaxViewHeight = 2048;
  58.  
  59. TYPE  PScreenL  = ^TScreenL;
  60.       TScreenL  = ARRAY[0..MaxViewWidth - 1] OF WORD;
  61.  
  62.       PScreenR  = ^TScreenR;
  63.       TScreenR  = ARRAY[0..MaxViewHeight - 1] OF PScreenL;
  64.  
  65.       PInterior = ^TInterior;
  66.       TInterior = OBJECT(TScroller)
  67.                      AutoScroll : BOOLEAN;
  68.                      MaxDim     : TPoint;
  69.                      CurLoc     : TPoint;
  70.                      TopPtr     : PScreenR;
  71.                      CONSTRUCTOR Init(VAR Bounds : TRect; Limits : TPoint;
  72.                                           Color : BYTE; AHScrollBar, AVScrollBar : PScrollBar);
  73.                      CONSTRUCTOR Load(VAR S : TStream);
  74.                      PROCEDURE Store(VAR S : TStream);
  75.                      PROCEDURE Draw; VIRTUAL;
  76.                      PROCEDURE PrintChar(Ch : CHAR; VAR TextAttr : BYTE);
  77.                      DESTRUCTOR Done; VIRTUAL;
  78.                   END;
  79.  
  80.       ParmsFld  = ARRAY[1..9] OF BYTE;
  81.  
  82.       PANSIView = ^TANSIView;
  83.       TANSIView = OBJECT(TWindow)
  84.                      UseANSI    : BOOLEAN;
  85.                      StateInfo  : BYTE;
  86.                      ESCBuf     : STRING[126];
  87.                      ANSIParms  : ParmsFld;
  88.                      ParmsIdx   : BYTE;
  89.                      EndString  : CHAR;
  90.                      CurHold    : TPoint;
  91.  
  92.                      TextAttr : BYTE;
  93.                      Interior : PInterior;
  94.                      CONSTRUCTOR Init(Bounds : TRect; Limits : TPoint; WnTitle : STRING; WindowNo : WORD);
  95.                      CONSTRUCTOR Load(VAR S : TStream);
  96.                      PROCEDURE Store(VAR S : TStream);
  97.                      FUNCTION  ProcessChar(Ch : CHAR) : BOOLEAN;
  98.  
  99.                      PROCEDURE PrintLN(s : STRING);
  100.                      PROCEDURE Print(s : STRING);
  101.                      PROCEDURE PrintChar(Ch : CHAR);
  102.                      PROCEDURE PutChar(X, Y : WORD; Ch : CHAR; Attr : BYTE);
  103.  
  104.                      PROCEDURE CursorOn;
  105.                      PROCEDURE CursorOff;
  106.                      PROCEDURE AutoScrollOn;
  107.                      PROCEDURE AutoScrollOff;
  108.  
  109.                      PROCEDURE ClrScr;
  110.                      PROCEDURE ClrEol;
  111.                      PROCEDURE DelLine;
  112.                      PROCEDURE GotoXY(X,Y : WORD);
  113.                      PROCEDURE HighVideo;
  114.                      PROCEDURE InsLine;
  115.                      PROCEDURE LowVideo;
  116.                      PROCEDURE TextBackground(Color : BYTE);
  117.                      PROCEDURE TextColor(Color : BYTE);
  118.                      FUNCTION WhereX : BYTE;
  119.                      FUNCTION WhereY : WORD;
  120.                   END;
  121.  
  122. CONST RANSIView: TStreamRec = (
  123.          ObjType: 7200;
  124.          VmtLink: Ofs(TypeOf(TANSIView)^);
  125.          Load:    @TANSIView.Load;
  126.          Store:   @TANSIView.Store
  127.       );
  128.  
  129.       RInterior: TStreamRec = (
  130.          ObjType: 7201;
  131.          VmtLink: Ofs(TypeOf(TInterior)^);
  132.          Load:    @TInterior.Load;
  133.          Store:   @TInterior.Store
  134.       );
  135.  
  136. PROCEDURE RegisterANSIView;
  137.  
  138. Implementation
  139.  
  140. {----------------------------------------------------------------------------}
  141.  
  142. FUNCTION Min(X,Y : INTEGER) : INTEGER; ASSEMBLER;
  143. ASM
  144.    MOV   AX,X
  145.    CMP   AX,Y
  146.    JLE   @@1
  147.    MOV   AX,Y
  148. @@1:
  149. END;
  150.  
  151. FUNCTION Max(X,Y : INTEGER) : INTEGER; ASSEMBLER;
  152. ASM
  153.    MOV   AX,X
  154.    CMP   AX,Y
  155.    JGE   @@1
  156.    MOV   AX,Y
  157. @@1:
  158. END;
  159.  
  160. {----------------------------------------------------------------------------}
  161.  
  162. CONSTRUCTOR TInterior.Init;
  163. VAR   i,j : WORD;
  164. BEGIN
  165.    TScroller.Init(Bounds,AHScrollBar,AVScrollBar);
  166.    MaxDim     := Limits;
  167.    AutoScroll := TRUE;
  168.    CurLoc.X   := 0;
  169.    CurLoc.Y   := 0;
  170.    TopPtr := MemAlloc(MaxDim.Y * SIZEOF(PScreenR));     {Allocate All Y Coords}
  171.    IF TopPtr = NIL THEN
  172.       BEGIN
  173.          TScroller.Done;
  174.          FAIL
  175.       END;
  176.    FOR i := 0 TO MaxDim.Y - 1 DO BEGIN                  {Now for each line}
  177.       TopPtr^[i] := MemAlloc(MaxDim.X * SIZEOF(WORD));
  178.       IF TopPtr^[i] = NIL THEN
  179.          BEGIN
  180.             IF i > 0 THEN
  181.                FOR j := 0 TO i - 1 DO
  182.                   FREEMEM(TopPtr^[j],MaxDim.X * SIZEOF(WORD));
  183.             FREEMEM(TopPtr,MaxDim.Y * SIZEOF(PScreenR));
  184.             TScroller.Done;
  185.             FAIL
  186.          END
  187.       ELSE
  188.          MoveChar(TopPtr^[i]^,' ',Color,MaxDim.X)
  189.    END;
  190.    GrowMode := gfGrowHiX + gfGrowHiY;
  191.    DragMode := dmLimitLoX + dmLimitLoY;
  192.    SetLimit(MaxDim.X,MaxDim.Y);
  193. END;
  194.  
  195. CONSTRUCTOR TInterior.Load;
  196. VAR   i,j : INTEGER;
  197.       ok  : BOOLEAN;
  198.       B   : TDrawBuffer;
  199. BEGIN
  200.    TScroller.Load(S);
  201.    S.Read(AutoScroll,SIZEOF(AutoScroll));
  202.    S.Read(CurLoc,SIZEOF(CurLoc));
  203.    S.Read(MaxDim,SIZEOF(MaxDim));
  204.    TopPtr := MemAlloc(MaxDim.Y * SIZEOF(PScreenR));
  205.    ok := (TopPtr <> NIL);
  206.    FOR i := 0 TO MaxDim.Y - 1 DO BEGIN
  207.       S.Read(B,MaxDim.X * SIZEOF(WORD));
  208.       IF ok THEN
  209.          BEGIN
  210.             TopPtr^[i] := MemAlloc(MaxDim.X * SIZEOF(WORD));
  211.             ok := ok AND (TopPtr^[i] <> NIL);
  212.             IF ok THEN
  213.                MOVE(B,TopPtr^[i]^,MaxDim.X * SIZEOF(WORD))
  214.             ELSE
  215.                IF i > 0 THEN
  216.                   FOR j := 0 TO i - 1 DO
  217.                      FREEMEM(TopPtr^[j],MaxDim.X * SIZEOF(WORD));
  218.          END
  219.    END;
  220.    IF NOT ok THEN
  221.       BEGIN
  222.          FREEMEM(TopPtr,MaxDim.Y * SIZEOF(PScreenR));
  223.          TScroller.Done;
  224.          FAIL
  225.       END;
  226.    GrowMode := gfGrowHiX + gfGrowHiY;
  227.    SetLimit(MaxDim.X,MaxDim.Y)
  228. END;
  229.  
  230. PROCEDURE TInterior.Store;
  231. VAR   i : INTEGER;
  232. BEGIN
  233.    TScroller.Store(S);
  234.    S.Write(AutoScroll,SIZEOF(AutoScroll));
  235.    S.Write(CurLoc,SIZEOF(CurLoc));
  236.    S.Write(MaxDim,SIZEOF(MaxDim));
  237.    FOR i := 0 TO MaxDim.Y - 1 DO
  238.       S.Write(TopPtr^[i]^,MaxDim.X * SIZEOF(WORD));
  239. END;
  240.  
  241. PROCEDURE TInterior.Draw;
  242. VAR   Y : INTEGER;
  243. BEGIN
  244.    FOR Y := 0 TO Size.Y - 1 DO
  245.       WriteLine(0,Y,Size.X,1,TopPtr^[Delt